<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="teacher/teacher-common::commonCss(~{::title},~{},~{::script},~{::style})">
    <title>JAVA在线考试-学生列表</title>

    <script th:src="@{/laydate/laydate.js}"></script>
    <style>
        .body{
            background-color: #f8f8f8;
        }
        .layui-table-cell {
            text-align: center;
            height: auto;
            white-space: normal;
        }
        .layui-table img {
            width: 70px;
            max-height: 70px;
        }
        .layui-form-select dl {
            max-height: 250px;
        }
        img[src=""], img:not([src]) {
            opacity: 0;
        }
    </style>

</head>
<script th:inline="javascript">
    layui.use(['table','element','laydate','form'], function(){
        var table = layui.table;
        var element = layui.element;
        var laydate = layui.laydate;
        var form = layui.form;

        laydate.render({
            elem: '#search-createTime'
            ,range: true
        });

        $("#searchBtn").click(function () {
            reload();
        });
        $("#resetBtn").click(function () {
            $("#searchUserInfoForm")[0].reset();
            tableIns.reload({
                where: {
                    "msg":"",
                    "code":"",
                    "data": {
                        "name": '',
                        "username": ''
                    }
                }
                , page: {
                    curr: 1
                }
            });
        });

        var tableIns = table.render({
            elem: '#userTable'
            , url: '/user/listStudentForPage'
            , contentType: 'application/json'
            , method: 'post'
            , where: {
                 "msg":"",
                     "code":"",
                     "data": {
                        "username": $('#search-username').val(),
                         "name": $('#search-name').val()
                 }
             }
            , defaultToolbar: []
            , page: true
            , limits: [5, 10, 20]
            , limit: 10
            , cols: [
            [
                {field: 'id', title: 'ID', hide: true}
                , {field: 'username', title: '用户名'}
                , {field: 'name', title: '姓名'}
                , {field: 'img', title: '头像', templet: function (d) {
                    var fileName = d.img;
                    return '<div><img src="http://rb5o4pf4r.hn-bkt.clouddn.com/' + fileName + '" alt="暂无图片"></div>'
                }}
                , {field: 'email', title: '邮箱'}
                , {field: 'phone', title: '手机号'}
            ]
        ]
    ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
            return {
                "code": res.result.code, //解析接口状态
                "msg": res.message, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.records //解析数据列表
            };
        }
    });

        function reload() {
            tableIns.reload({
                where: {
                    "msg":"",
                    "code":"",
                    "data": {
                        "username": $('#search-username').val(),
                        "name": $('#search-name').val()
                    }
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        }

    });
</script>
<body>
<div class="layui-layout layui-layout-admin">

    <div th:replace="teacher/teacher-common::header"></div>
    <div th:replace="teacher/teacher-common::side('student')"></div>

    <div class="layui-body body">
        <div class="layui-fluid" style="padding: 15px;">
            <div class="layui-card">
                <form class="layui-form layui-card-header" style="padding: 15px" lay-filter="searchUserInfoForm" id="searchUserInfoForm">
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width:150px;">
                            <input class="layui-input" id="search-username" autocomplete="off" placeholder="用户名">
                        </div>
                        <div class="layui-inline" style="width:150px;">
                            <input class="layui-input" id="search-name" autocomplete="off" placeholder="姓名">
                        </div>
                        <div class="layui-inline" style="float: right;">
                            <button type="button" class="layui-btn" id="searchBtn">
                                <i class="layui-icon layui-icon-search"></i> 搜索
                            </button>
                            <button  type="button" class="layui-btn" id="resetBtn">重置</button>
                        </div>

                    </div>
                </form>

                <div class="layui-card-body">
                    <div style="padding-bottom:10px;">
                        <table class="layui-hide" id="userTable" lay-skin="line" lay-filter="userTable">
                        </table>
                    </div>
                </div>

            </div>
        </div>

    </div>

    <div th:replace="teacher/teacher-common::footer"></div>
</div>

</body>
</html>